#include "SceneMgr.h"
#include "AnimMgr.h"
#include "Game/Game.h"

namespace LTGame
{
	SceneMgr::SceneMgr()
		: m_data(NULL)
		, m_script(NULL)
		, m_map(NULL)
	{

	}

	SceneMgr::~SceneMgr()
	{
		freeRes();
	}

	void SceneMgr::loadRes(int levelId, bool& isStep)
	{
		if ( !isStep )	return;

		static int loadingProgress = 0;
		bool isStepLoadAnim = false;
		switch( loadingProgress )
		{
		case 0: m_data = new SceneData(levelId); break;
		case 10: m_script = new ScriptData(levelId); break;
		case 20: m_map = new Map(levelId); break;
		case 30:
			isStepLoadAnim = true;
			AnimMgr::getInstance()->loadRes(levelId, isStepLoadAnim);
			break;
		case 40:
			CCGame->m_objMgr->initActor();
		case 50:
			CCGame->m_objMgr->sortActor();
			break;
		}

		if ( !isStepLoadAnim ){ loadingProgress += 10;}
		if ( loadingProgress > 50 )
		{
			isStep = false;
			loadingProgress = 0;
		}

	}

	void SceneMgr::freeRes()
	{
		CC_SAFE_DELETE(m_data);
		CC_SAFE_DELETE(m_map);
		CC_SAFE_DELETE(m_script);
		AnimMgr::getInstance()->freeRes();
		CCGame->m_objMgr->releaseContainer();
		CCGame->m_objMgr->curHero= NULL;
	}


}